<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace custom;
/**
 * Description of Util
 *
 * @author wang
 */
class Util {
    //put your code here
    /**
     * 随机生成指定长度字符串（小写字母，数字）
     * @param type $length
     * @return string
     */
    public static function generate_random_lowerletter_number( $length = 32 ) {
        // 密码字符集，可任意添加你需要的字符
        $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
        $result = '';
        for ( $i = 0; $i < $length; $i++ )  {
            $result .= $chars[ mt_rand(0, strlen($chars) - 1) ];
        }
        return $result;
    }
    
    /**
     * 随机生成指定长度字符串（数字）
     * @param type $length
     * @return string
     */
    public static function generate_random_number( $length = 6 ) {
        // 密码字符集，可任意添加你需要的字符
        $chars = '0123456789';
        $result = '';
        for ( $i = 0; $i < $length; $i++ )  {
            $result .= $chars[ mt_rand(0, strlen($chars) - 1) ];
        }
        return $result;
    }
    
    public static function isMobile($mobile) {
        if (!is_numeric($mobile)) {
            return false;
        }
        
        return preg_match('#^(((13)|(14)|(15)|(17)|(18))+\d{9})$#', $mobile) ? true : false;
    }
}
